unsigned replace_byte(unsigned x, int i, unsigned char b){
    return (x&~(0xff<<i*8))|unsigned(b)<<i*8;
}
#include<iostream>
int main() {
    unsigned x = 0x89abcdef, y = 0x76543210;
    unsigned z = (y & 0xffffff00) | (x & 0xff);
    std::cout<<std::hex<<z<<std::endl;
    std::cout
        <<replace_byte(0x12345678,2,0xab)<<std::endl
        <<replace_byte(0x12345678,0,0xab);
    return 0;
}